<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="../header.jsp"%>
<!--  显示内容 -->
	<!-- Content Wrapper. Contains page content -->
      <div class="content-wrapper" style="font-family: '微软雅黑';">
        <!-- Content Header (Page header) -->
        <section class="content-header">
          <h1>
            ${module}
            <small>广告编辑</small>
          </h1>
          <ol class="breadcrumb">
            <li><a href='<c:url value="/main/stage/main"/>'><i class="fa fa-dashboard"></i>主页</a></li>
            <li class="active">广告管理</li>
          </ol>
        </section>
        
        <!-- Main content -->
        <section class="content">
          <div class="row">
            <div class="col-xs-12">
              <div class="box" style="min-width: 920px;">
                <div class="box-header" style="padding: 20px;">
                  <div class="col-xs-12">
                  	<div class="col-xs-6" style="text-align: center;">
                  		<span>广告类型：</span>
                  		<select class="form-control" id="type" onchange="chooseType(this[selectedIndex].value)">
                  			<option value="-1">--请选择--</option>
                  			<option value="2" <c:if test="${advert.type eq 2}">selected="selected"</c:if>>推广</option>
                  			<option value="1" <c:if test="${advert.type eq 1}">selected="selected"</c:if>>指定商品广告</option>
                  			<option value="3" <c:if test="${advert.type eq 3}">selected="selected"</c:if>>未指定商品广告</option>
                  			<option value="4" <c:if test="${advert.type eq 4}">selected="selected"</c:if>>未指定商品广告</option>
                  		</select>
                  	</div>
                  	<input type="hidden" value="${advert.advertid}" id="advertId"/>
                  	<input type="hidden" id="token" class="form-control" value="${token}"/>
                  	<div class="col-xs-6"  style="text-align: center;">
                  		<span>广告状态：</span>
                  		<select class="form-control" id="status">
                  			<option value="-1">--请选择--</option>
                  			<option value="0" <c:if test="${advert.status eq 0}">selected="selected"</c:if>>禁用</option>
                  			<option value="1" <c:if test="${advert.status eq 1}">selected="selected"</c:if>>可用</option>
                  		</select>
                  	</div>
                  </div>
                  <div style="clear: both;"></div>
                  <hr/>
                  <div class="col-xs-12">
                  	<div class="col-xs-6" style="text-align: center;">
                  		<span>开始时间：</span>
                  		<input type="text" id="startTime" class="form-control" value="${advert.starttime}"/>
                  	</div>
                  	<div class="col-xs-6"  style="text-align: center;">
                  		<span>结束时间：</span>
                  		<input type="text" id="endTime" class="form-control" value="${advert.endtime}"/>
                  	</div>
                  </div>
                  <div style="clear: both;"></div>
                  <hr/>
                  	<c:if test="${advert.type==2}">
	                   <div class="col-xs-12">
	                  	<div class="col-xs-6" style="text-align: center;">
	                  		<span>原价：</span>
		                  		<input type="text" class="form-control" id="originalPrice" value="${advert.originalPrice}" disabled="disabled"/>
	                  	</div>
	                  	<div class="col-xs-6" style="text-align: center;">
	                  		<span>折扣价：</span>
		                  		<input type="text" class="form-control" id="discountPrice" value="${advert.discountPrice}"  disabled="disabled"/>
	                  	</div>
	                  </div>
	                  <div style="clear: both;"></div>
	                  <hr/>
           		  </c:if>
           		  <c:if test="${advert.type==1}">
           		  	<div class="col-xs-12">
	                  	<div class="col-xs-6" style="text-align: center;">
	                  		<span>原价：</span>
		                  		<input type="text" class="form-control" id="originalPrice" value="${advert.originalPrice}" />
	                  	</div>
	                  	<div class="col-xs-6" style="text-align: center;">
	                  		<span>折扣价：</span>
		                  		<input type="text" class="form-control" id="discountPrice" value="${advert.discountPrice}"/>
	                  	</div>
	                  </div>
	                  <div style="clear: both;"></div>
	                  <hr/>
           		  </c:if>
                  <div class="col-xs-12">
                  	<div class="col-xs-6" style="text-align: center;">
                  		<span>地区：</span>
                  			${manager.cityName}
                  		<c:choose>
                  			<c:when test="${manager.cityName eq 'allCity'}">
                  				<select class="form-control" id="cityname">
                  					<option value="全国">全国</option>
                  					<c:forEach items="${cities}" var="city">
	                  					<option value="${city.name}" <c:if test="${city.name eq advert.cityname}">selected="selected"</c:if>>${city.name}</option>
                  					</c:forEach>
                  				</select>
                  			</c:when>
                  			<c:otherwise>
                  				<input id="cityname" value="${advert.cityname}" class="form-control" disabled="disabled"/>
                  			</c:otherwise>
                  		</c:choose>
                  	</div>
          			<div class="col-xs-6" style="text-align: center;">
     					页面链接
     					<input id="url" value="${advert.url}" class="form-control" <c:if test="${advert.type==1}"> disabled="disabled"</c:if>/>
    				</div>
                  </div>
                  <div style="clear: both;"></div>
                  <hr/>
                  <div class="col-xs-12">
                  	<div class="col-xs-3" style="text-align: center;">
                  	</div>
                  	<div class="col-xs-6" style="text-align: center;">
                  		广告图
                  		<div style="margin: 10px 0;" id="images">
                  			<a id="negativeIdPath" title="广告图" href="${advert.picpath}@750w" data-lightbox="example-2">
		                  		<img class="pic" id="negativeIdPathPic" alt="广告图" src="${advert.picpath}">
                  			</a>
                  		</div>
                  	</div>
                  	<div class="col-xs-3" style="text-align: center;">
                  	</div>
                  </div>
                  <div style="clear: both;"></div>
                  <div class="col-xs-12">
                  	<div class="col-xs-4" style="text-align: center;">
                  	</div>
                  	<div class="col-xs-4" style="text-align: center;padding-left: 120px;">
                  		<%--用来作为文件队列区域--%>
				        <div id="fileQueue"></div>
				        <input type="file" name="uploadify" id="uploadify"/>
				        <!-- <p>
				            <a href="javascript:$('#uploadify').uploadify('upload')">上传</a>| 
				            <a href="javascript:$('#uploadify').uploadify('cancel')">取消上传</a>
				        </p> -->
                  	</div>
                  	<div class="col-xs-4" style="text-align: center;">
                  	</div>
                  </div>
                  <div style="clear: both;"></div>
                  <hr/>
                  <div class="col-xs-12">
                  	<h5>广告描述：</h5>
                  	<textarea class="form-control" rows="4" id="descption" placeholder="请输入广告描述">${advert.descption}</textarea>
                  </div>
                  <div style="clear: both;"></div>
                  <hr/>
                  <div style="text-align: center;margin-top: 50px;">
               			<button class="btn btn-success" style="width: 100px;" onclick="updateAdvert(${advert.advertid})">确定</button>
               			<button class="btn btn-success" style="width: 100px;" onclick="cancel()">取消</button>
                </div><!-- /.box-header -->
              </div><!-- /.box -->
            </div><!-- /.col -->
          </div><!-- /.row -->
          
          <!--  显示下面的分页控件  -->
          
        </section><!-- /.content -->
       </div>
       
      <jsp:include page="../js.jsp"/>
	<%@ include file="../footer.jsp"%>
	
	<script type="text/javascript">
		$(document).ready(function() {
			var carrousel = $( ".carrousel" );

			$( ".portrait" ).click( function(e){
			  var src = $(this).find(".pic").attr( "data-src-wide" );
			  carrousel.find("img").attr( "src", src );
			  carrousel.fadeIn( 200 );
			});

			carrousel.find( ".close" ).click( function(e){
			  carrousel.find( "img" ).attr( "src", '' );
			  carrousel.fadeOut( 200 );
			} );
			$("#uploadify").uploadify({
                //指定swf文件
                'swf': '<c:url value="/Js/uploadify/uploadify.swf"/>',
                //后台处理的页面
                'uploader': '<c:url value="/advert/upload/advertpic"/>?advertid=${advert.advertid}',
                //按钮显示的文字
                'buttonText': '换一张',
                //显示的高度和宽度，默认 height 30；width 120
                //'height': 15,
                //'width': 80,
                //上传文件的类型  默认为所有文件    'All Files'  ;  '*.*'
                //在浏览窗口底部的文件类型下拉菜单中显示的文本
                'fileTypeDesc': 'Image Files',
                //允许上传的文件后缀
                'fileTypeExts': '*.gif; *.jpg; *.png',
                //发送给后台的其他参数通过formData指定
                //'formData': { 'someKey': 'someValue', 'someOtherKey': 1 },
                //上传文件页面中，你想要用来作为文件队列的元素的id, 默认为false  自动生成,  不带#
                //'queueID': 'fileQueue',
                //选择文件后自动上传
                'auto': true,
                //设置为true将允许多文件上传
                'multi': false,
                'fileObjName':'pic',
                'method':"Post",
                'onUploadSuccess': function (file, data, response) {
                	var url = jQuery.parseJSON(data).datas;
                    $("#negativeIdPathPic").attr("src",url.toString());
                    $("#negativeIdPath").attr("href",url.toString()+"@750w");
                }
            });
		});
		
		
		
		$('#startTime').datetimepicker({
			lang:'ch',
			format:"Y-m-d H:i", 
			timepicker:true
			}).attr("readonly","readonly");
		$('#endTime').datetimepicker({
			lang:'ch',
			format:"Y-m-d H:i",
			timepicker:true
			}).attr("readonly","readonly");
		function updateAdvert(id){
			var advertid = 0;
			var type = -1;
			var status=-1;
			var starttime="";
			var endtime="";
			var originalPrice=0.0;
			var discountPrice=0.0;
			var cityname="";
			var descption="";
			var url = "";
			if($("#advertId").val()){
				advertId=$("#advertId").val();
			}
			if($("#type").val()){
				type=$("#type").val();
			}
			if($("#status").val()){
				status=$("#status").val();
			}
			if($("#startTime").val()){
				starttime=$("#startTime").val();
			}
			if($("#endTime").val()){
				endtime=$("#endTime").val();
			}
			if($("#originalPrice").val()){
				originalPrice=$("#originalPrice").val();
			}
			if($("#discountPrice").val()){
				discountPrice=$("#discountPrice").val();
			}
			if($("#cityname").val()){
				cityname=$("#cityname").val();
			}
			if($("#descption").val()){
				descption=$("#descption").val();
			}
			if($("#url").val()){
				url=$("#url").val();
			}
			var params = {
					advertid:advertId,
					type:type,
					status:status,
					starttime:starttime,
					endtime:endtime,
					originalPrice:originalPrice,
					discountPrice:discountPrice,
					cityname:cityname,
					url:url,
					descption:descption
			};
			$.post('<c:url value="/advert/update"/>',params,function(data){
				if(data.code==0){
					swal({
						title:"操作成功！",
						type:"success",
						closeOnConfirm: true,
						confirmButtonText:"确  定"
					},
					function (){
						window.location.href='<c:url value="/advert/list"/>'; 
					});
				}else{
					swal({
						title:"操作失败！",
						type:"error",
						closeOnConfirm: true,
						confirmButtonText:"确  定"
					});
				}
			},"json");
		}
		function candel(){
			window.location.href='<c:url value="/advert/list"/>'; 
		}
		function chooseType(val){
			if(val==2){
				$("#originalPrice").val(0);
				$("#originalPrice").attr("disabled","disabled");
				$("#discountPrice").val(0);
				$("#discountPrice").attr("disabled","disabled");
				$("#url").removeAttr("disabled");
			}
			if(val==3){
				$("#originalPrice").val(0);
				$("#originalPrice").attr("disabled","disabled");
				$("#discountPrice").val(0);
				$("#discountPrice").attr("disabled","disabled");
				$("#url").attr("disabled","disabled");
			}
			if(val==1){
				$("#url").attr("disabled","disabled");
				$("#originalPrice").removeAttr("disabled");
				$("#discountPrice").removeAttr("disabled");
			}
		}
	</script>
	</body>
</html>